package com.example.ch8;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.ch5.Person;

/**
 * Servlet implementation class DoRequestServlet
 */
public class DoRequestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoRequestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Person p = new Person("Init-person");
		request.setAttribute("ch5.person", p);
		Cookie cookie = new Cookie("author", "Dylan-hu");
		response.addCookie(cookie);
		RequestDispatcher dispatcher = request.getRequestDispatcher("getRequest.jsp");
		dispatcher.forward(request, response);
	}

}
